package com.googlecode.boliang.q10;

public class KthRetrieve {

	public int getKthNumFromTail(int k, LinkedNode firstNode) {

		LinkedNode leftPointer = firstNode;
		LinkedNode rightPointer = firstNode;
		int j = 1;

		while (j < k) {
			rightPointer = rightPointer.getNextNode();
			j++;
		}
		System.out.println(rightPointer.getNodeValue());
		System.out.println(leftPointer.getNodeValue());

		while (rightPointer.getNextNode() != null) {
			rightPointer = rightPointer.getNextNode();
			leftPointer = leftPointer.getNextNode();
		}
		return leftPointer.getNodeValue();
	}
}
